home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / rcs / ident.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  4.4 KB  |  169 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Distributed under license by the Free Software Foundation, Inc.
  3.  
  4. This file is part of RCS.
  5.  
  6. RCS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. RCS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with RCS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. Report problems and direct all questions to:
  21.  
  22.     rcs-bugs@cs.purdue.edu
  23.  
  24. */
  25.  
  26. /*
  27.  *                     RCS identification operation
  28.  */
  29. #ifndef lint
  30. static char rcsid[]=
  31. "$Header: /usr4/rock/system/pisces/rcs/RCS/ident.c,v 1.1 90/05/21 13:42:53 neath Exp $Purdue CS";
  32. #endif
  33.  
  34. /* $Log:    ident.c,v $
  35.  * Revision 1.1  90/05/21  13:42:53  neath
  36.  * Initial revision
  37.  * 
  38.  * Revision 4.5  89/05/01  15:11:54  narten
  39.  * changed copyright header to reflect current distribution rules
  40.  * 
  41.  * Revision 4.4  87/10/23  17:09:57  narten
  42.  * added exit(0) so exit return code would be non random
  43.  * 
  44.  * Revision 4.3  87/10/18  10:23:55  narten
  45.  * Updating version numbers. Changes relative to 1.1 are actually relative
  46.  * to 4.1
  47.  * 
  48.  * Revision 1.3  87/07/09  09:20:52  trinkle
  49.  * Added check to make sure there is at least one arg before comparing argv[1]
  50.  * with "-q".  This necessary on machines that don't allow dereferncing null
  51.  * pointers (i.e. Suns).
  52.  * 
  53.  * Revision 1.2  87/03/27  14:21:47  jenkins
  54.  * Port to suns
  55.  * 
  56.  * Revision 1.1  84/01/23  14:50:03  kcs
  57.  * Initial revision
  58.  * 
  59.  * Revision 4.1  83/05/10  16:31:02  wft
  60.  * Added option -q and input from reading stdin.
  61.  * Marker matching is now done with trymatch() (independent of keywords).
  62.  * 
  63.  * Revision 3.4  83/02/18  17:37:49  wft
  64.  * removed printing of new line after last file.
  65.  *
  66.  * Revision 3.3  82/12/04  12:48:55  wft
  67.  * Added LOCKER.
  68.  *
  69.  * Revision 3.2  82/11/28  18:24:17  wft
  70.  * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
  71.  *
  72.  * Revision 3.1  82/10/13  15:58:51  wft
  73.  * fixed type of variables receiving from getc() (char-->int).
  74. */
  75.  
  76. #include  "rcsbase.h"
  77. #define fflsbuf _flsbuf
  78. /* redefinition of _flsbuf in putc not needed */
  79. #ifndef lint
  80. static char rcsbaseid[] = RCSBASE;
  81. #endif
  82.  
  83. extern enum markers trymatch();
  84.  
  85. int quietflag;
  86.  
  87. main(argc, argv)
  88. int  argc; char  *argv[];
  89. /*  Ident searches the named files for all occurrences
  90.  *  of the pattern $keyword:...$, where the keywords are
  91.  *  Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
  92.  */
  93.  
  94. {
  95.    FILE *fp, *fopen();
  96.  
  97.    quietflag = false;
  98.    if (argc > 1 && strcmp("-q",argv[1])==0) {
  99.         quietflag = true;
  100.         argc--; argv++;
  101.    }
  102.  
  103.    if (argc<2) {
  104.      if ((scanfile(stdin) == 0) && !quietflag)
  105.         VOID fprintf(stderr, "ident warning: no id keywords in input\n");
  106.     exit(0);
  107.    }
  108.  
  109.    while ( --argc > 0 ) {
  110.       if ( (fp = fopen(*++argv, "r") ) == NULL ) {
  111.          VOID fprintf(stderr,  "ident error: can't open %s\n", *argv);
  112.          continue;
  113.       } else {
  114.          VOID printf( "%s:\n", *argv);   /*  print file name  */
  115.      if ((scanfile(fp) == 0) && !quietflag)
  116.         VOID fprintf(stderr, "ident warning: no id keywords in %s\n", *argv);
  117.      if (argc>1) putchar('\n');
  118.      VOID fclose(fp);
  119.       }
  120.    }
  121.    exit(0);
  122. }
  123.  
  124.  
  125. int scanfile(file)
  126. FILE * file;
  127. /* Function: scan an open file with descriptor file for keywords.
  128.  * Returns the number of matches.
  129.  */
  130. {
  131.    register int matchcount;
  132.    register int c;
  133.  
  134.  
  135.    matchcount = 0;
  136.    while( (c=getc(file)) != EOF) {
  137.       if ( (char)c==KDELIM)
  138.      matchcount += match(file);
  139.    }
  140.    return matchcount;
  141. }
  142.  
  143.  
  144.  
  145. match(fp)   /* group substring between two KDELIM's; then do pattern match */
  146. FILE *fp;
  147. {
  148.    char line[keyvallength];
  149.    register int c;
  150.    register char * tp;
  151.  
  152.    tp = line;
  153.    while( (c = getc(fp)) != KDELIM ) {
  154.       *tp++ = c;
  155.       if ( c==EOF || c=='\n' || tp>= line+keyvallength-2)
  156.          return(0);
  157.    }
  158.    *tp++ = c;     /*append trailing KDELIM*/
  159.    *tp   = '\0';
  160.    if (trymatch(line,true)!=Nomatch) {
  161.         VOID fprintf(stdout,"     $%s\n",line);
  162.         return(1);
  163.    } else {
  164.       /* no match; put trailing KDELIM back into input */
  165.       VOID ungetc(c,fp );
  166.       return(0);
  167.    }
  168. }
  169.